import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:hitutor/UI/Account/ChangePassword2.dart';
import 'package:hitutor/UI/Account/ForgetPassword.dart';
import 'package:hitutor/Util/Global.dart';
import 'package:hitutor/Util/HttpGo.dart';
import 'package:hitutor/Util/MyColor.dart';
import 'package:hitutor/Util/PageUtil.dart';
import 'package:hitutor/Widget/MyButton.dart';
import 'package:hitutor/Widget/MyDialog.dart';
import 'package:hitutor/Widget/MyInput.dart';
import 'package:hitutor/Widget/MyPage.dart';

class ChangePassword extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ChangePsw();
  }
}

class _ChangePsw extends State<ChangePassword> {
  TextEditingController oldPswController = TextEditingController();
  TextEditingController pswController = TextEditingController();
  TextEditingController pswController2 = TextEditingController();

  confirmClick() {
    if (oldPswController.text.isEmpty) {
      showToast("請輸入現在的密碼");
      return;
    }
    if (pswController.text.isEmpty) {
      showToast("請輸入新密碼");
      return;
    }
    if (pswController.text != pswController2.text) {
      showToast("兩次輸入的新密碼不一致");
      return;
    }
    HttpGo(context).post("/Member/ModifyPassword", {
      "studentId": Global.studentId,
      "oldPassword": oldPswController.text,
      "newPassword": pswController.text,
    }, (data) {
      PageUtil().back(context);
    }, (code, error) => showToast(error));
  }

  forgetPsw() {
    PageUtil().open(context, ForgetPassword());
  }

  @override
  Widget build(BuildContext context) {
    return MyPage(
        "變更密碼",
        Container(
            padding: EdgeInsets.all(20),
            child: Column(children: [
              // Container(
              //     alignment: Alignment.centerLeft,
              //     child: Text("為了保護你的帳號安全，請再次輸入密碼以進行下一步", style: TextStyle(fontSize: 11, color: MyColor.Black))),
              Container(
                decoration: Global.getBg(MyColor.F3, 4),
                height: 32,
                margin: EdgeInsets.fromLTRB(0, 8, 0, 8),
                padding: EdgeInsets.only(left: 8),
                child: NormalInput(hintText: "請輸入現在的密碼", fontSize: 12, controller: oldPswController),
              ),
              Container(
                decoration: Global.getBg(MyColor.F3, 4),
                height: 32,
                margin: EdgeInsets.fromLTRB(0, 8, 0, 8),
                padding: EdgeInsets.only(left: 8),
                child: NormalInput(hintText: "新密碼", fontSize: 12, controller: pswController),
              ),
              Container(
                decoration: Global.getBg(MyColor.F3, 4),
                height: 32,
                margin: EdgeInsets.fromLTRB(0, 8, 0, 48),
                padding: EdgeInsets.only(left: 8),
                child: NormalInput(hintText: "密碼確認", fontSize: 12, controller: pswController2),
              ),
              Button("確認", height: 32, bgColor: Color(0xff43bacc), width: double.infinity, radius: 4, fontSize: 13, onTap: confirmClick),
              TextBtn("忘記密碼？", height: 40, style: TextStyle(fontSize: 13, color: MyColor.Blue), onTap: forgetPsw)
            ])));
  }
}
